import { ContactModel } from '~/model/ContactModel'

export abstract class ContactSerializer {
  public static serialize(model: ContactModel): SentData {
    return {
      name: model.name,
      phone: model.phone,
      notes: model.notes,
    }
  }

  public static deserialize(data: ReceivedData): ContactModel {
    const model = new ContactModel()
    model.id = data.id
    model.name = data.name
    model.avatar = data.avatar || undefined
    model.phone = data.phone
    model.notes = data.notes
    return model
  }
}

interface SentData {
  name: string
  phone: string
  notes: string
}

export interface ReceivedData {
  id: number
  name: string
  avatar: string | null
  phone: string
  notes: string
}
